/*
 * Copyright (c) 2012-2013, CS Bakery. All rights reserved.
 */

package testCase;

/*
 * 	@release Final Release
 *	@author  Chan Ka Yan
 *	@version 2.4.1
 *
 * 	@release Release 2
 *	@author  Lee Cheuk Wang
 *	@version 1.1.5
 */


import org.junit.Test;
import junit.framework.TestCase;
import csBakery.*;

public class PriceListTest extends TestCase{
	private PriceList pricelist;
	private String filename = "";
	
	@Test
	public void testOpen_PriceListA(){
		filename = "test\\pricelistA.txt";
		pricelist = new PriceList(filename);
		String result = "ItemA $10.0\nItemB $20.0\nItemC $30.0\nItemD $40.0\nItemE $50.0\n";
		assertEquals(result, pricelist.toString());
	}
	
	@Test
	public void testOpen_PriceListB(){
		filename = "test\\pricelistB.txt";
		pricelist = new PriceList(filename);
		String result = "Bagel $30.0\nBaguette $60.6\nAish Merahrah $70.7\nBanana Bread $40.4\nBara Brith bread $50.5\n";
		assertEquals(result, pricelist.toString());
	}
	
	@Test
	public void testWrite_PriceListNew(){
		filename = "test\\pricelistC.txt";
		
		//Ensure that each pricelistC must be an empty .txt file
		PriceList.clearFile(filename);
		
		pricelist = new PriceList(filename);
		pricelist.addNewPrice("ItemA", 10);
		pricelist.addNewPrice("ItemB", 20);
		pricelist.addNewPrice("ItemC", 20);
		pricelist.addNewPrice("ItemD", 30);
		
		String result = "ItemA $10.0\nItemB $20.0\nItemC $20.0\nItemD $30.0\n";
		assertEquals(result, pricelist.toString());
		
		//Testing individual item
		assertEquals(10, pricelist.getPrice("ItemA"), 0);
		assertEquals(20, pricelist.getPrice("ItemB"), 0);
		assertEquals(20, pricelist.getPrice("ItemC"), 0);
		assertEquals(30, pricelist.getPrice("ItemD"), 0);
		assertEquals(0, pricelist.getPrice("butterfly"), 0);
	}
}
